package com.kuang.url;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class URLDown {

    public static void main(String[] args) throws IOException {
        //1.下载地址
        URL url = new URL("https://p1.music.126.net/7NZYtTE33EzQvGnblu31Fg==/109951165044253827.jpg?param=50y50");
        //2.连接到这个资源 HTTP
        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
        InputStream inputStream = urlConnection.getInputStream();

        FileOutputStream fos = new FileOutputStream("Net/src/f.jpg");

        byte[] buffer = new byte[1024];
        int len;
        if ((len = inputStream.read(buffer))!=-1){
            fos.write(buffer,0,len);
        }
    }

}
